package threadcreate01;

public class thread05 {
    public static void main(String[] args) {
        t123 t123 = new t123();
        Thread t1 = new Thread(t123, "张文鹏");
        Thread t2 = new Thread(t123, "王大锤");
        t2.start();
        t1.start();
    }

    public static class t123 implements Runnable {
        private static Integer i = 10;
        @Override
        public void run() {
            while (true) {
                synchronized (this) {
                    notifyAll();
                    if (i > 0) {
                        System.out.println(Thread.currentThread().getName() + i);
                        i--;
                        System.out.println(i);
                    } else {
                        break;
                    }
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
